

import re

global_data = {'userid': '36841', 'token': '2f3ce709b922dfabb71c3f645f9cb34b'}
test_data = '{"userid":"%{userid}", "token": "%{token}", "title":"python", "content":"python port test"}'

if re.search(r'%{\w+}',test_data):
    while re.search(r'%{\w+}',test_data):
        var_name= re.search(r'%{(\w+)}',test_data).group(1)
        value= global_data[var_name]
        test_data= re.sub(r'%{\w+}',value,test_data,1)
print(test_data)

